package com.breaker.kata.util;

import org.apache.commons.lang3.StringUtils;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import static org.assertj.core.api.AssertionsForInterfaceTypes.assertThat;

public class ArrayUtil {
    public static int[] stringToIntArray(String data) {
        if (StringUtils.isBlank(data)) {
            return new int[]{};
        }
        return Arrays.stream(data.split("_"))
                .map(Integer::parseInt)
                .mapToInt(it -> it)
                .toArray();
    }

    public static String[] stringToStringArray(String data) {
        if (StringUtils.isBlank(data)) {
            return new String[]{};
        }
        return Arrays.stream(data.split("_")).toArray(String[]::new);
    }

    public static void arrayIntEqual(int[] excepteds, int[] input) {
        for (int i = 0; i < excepteds.length; i++) {
            assertThat(input[i]).isEqualTo(excepteds[i]);
        }
    }

    public static void arrayStringEqual(String[] excepteds, String[] input) {
        for (int i = 0; i < excepteds.length; i++) {
            assertThat(input[i]).isEqualTo(excepteds[i]);
        }
    }

    public static void arrayIntEqual(int length, int[] excepteds, int[] input) {
        for (int i = 0; i < length; i++) {
            assert input[i] == excepteds[i];
        }
    }
}
